package com.corelib;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import com.corelib.config.AppConfig;
import com.corelib.eventbus.EventOne;
import com.corelib.fresco.FresoMainActivity;
import com.corelib.mvp.demo.login.LoginActivity;
import com.corelib.rxAndRetrofit.RetrofitUtils;
import com.corelib.rxAndRetrofit.UpdateInfoBean;
import com.corelib.utils.LogUtils;
import com.google.gson.Gson;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.Observer;
import rx.Scheduler;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class ScrollingActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scrolling);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        Logger.e(AppConfig.BASE_URL+"*********"+AppConfig.getVersionType());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_scrolling, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_mvp) {
            startActivity(new Intent(this,LoginActivity.class));
            return true;
        }else if(id == R.id.action_eventbus){
            startActivity(new Intent(this,EventOne.class));
            return true;
        }else if(id == R.id.action_retrofit2){

            //Call<UpdateInfoBean> call = RetrofitUtils.createAPIService().getUpdateInfo("98a35ce1ce0b454b9ab8f204c5bc0ebd","1");//post
            Call<UpdateInfoBean> call = RetrofitUtils.createAPIService().getUpdateInfoByGet();//get
            call.enqueue(new Callback<UpdateInfoBean>() {
                @Override
                public void onResponse(Call<UpdateInfoBean> call, Response<UpdateInfoBean> response) {
                    UpdateInfoBean bean = response.body();
                }

                @Override
                public void onFailure(Call<UpdateInfoBean> call, Throwable t) {

                }
            });
            return true;
        }else if(id==R.id.action_RXretrofit2){
            RetrofitUtils.createAPIService().getUpdateInfoByRxjava()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Observer<UpdateInfoBean>() {
                        @Override
                        public void onCompleted() {

                        }

                        @Override
                        public void onError(Throwable e) {

                        }

                        @Override
                        public void onNext(UpdateInfoBean updateInfoBean) {
                            Logger.t("obj").json(new Gson().toJson(updateInfoBean));
                        }
                    });
        }else if(id==R.id.action_fresco){
            startActivity(new Intent(this,FresoMainActivity.class));
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
